import gradio as gr

def toggle_color(current_color):
    next_color = "blue" if current_color == "red" else "red"
    return next_color


def update_button(current_color):
    next_color = "blue" if current_color == "red" else "red"
    new_class = "btn-blue" if next_color == "blue" else "btn-red"
    return next_color, gr.Button(elem_classes=new_class)


with gr.Blocks(css="""
    .btn-red { background: red !important; color: white !important; }
    .btn-blue { background: blue !important; color: white !important; }
""") as demo:
    color_state = gr.State(value="blue")
    btn = gr.Button("点击切换颜色", elem_classes="btn-blue")

    btn.click(
        update_button,
        inputs=[color_state],
        outputs=[color_state, btn]
    )

demo.launch()